package cn.com.huzo.webapp.controller;

import cn.com.huzo.service.dashboard.DashBoardManager;
import cn.com.huzo.service.oa.BulletinManager;
import cn.com.huzo.service.oa.ToDoManager;
import huzofw.common.web.controller.BaseFormController;
import huzofw.model.entities.identity.IdentityUserEntity;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 仪表板控制器
 * <p>
 * @author 吴旭
 */
@Controller
public class DashBoardController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性">    
    @Resource(name = "DashBoardManager")
    private DashBoardManager _manager;

    @Resource(name = "BulletinManager")
    private BulletinManager _manager_bulletin;

    @Resource(name = "ToDoManager")
    private ToDoManager _manager_todo;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到系统主画面
     * <p>
     * @param session 系统会话对象
     * @return
     * @throws java.lang.Exception
     */
    @RequestMapping("dashBoard.html")
    public ModelAndView redirectDashBoardWnd(HttpSession session) throws Exception {
        ModelAndView view = new ModelAndView();

        IdentityUserEntity identityUser = (IdentityUserEntity) session.getAttribute("IdentityUser");
        Map<String, Object> _dashBoardData = _manager.fetchDashBoardData(identityUser.getEmployeeId());
        view.addObject("NewMpsCount", MapUtils.getInteger(_dashBoardData, "NewMpsCount"));
        view.addObject("PoNotices", MapUtils.getInteger(_dashBoardData, "PoNotices"));
        view.addObject("Bulletins", _manager_bulletin.fetchForDashboard());
        view.addObject("ToDoItems", _manager_todo.fetchForCount(null));
        view.setViewName("dashBoard.def");

        return view;
    }
    // </editor-fold>
}
